package net.greyar.single;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import net.greyar.gear.Machine;
import net.greyar.model.Server;
import net.greyar.model.User;
import net.greyar.theory.Symbol;

public class Session {
	public static User getUser(HttpServletRequest request) throws IOException {
		User user = (User) request.getSession().getAttribute("user");
		if (user == null) {
			user = new User(new Machine(new Server(), "grid", Catalog.getRules("grid")));
			user.getGrid().input((Symbol.parse("(user " + user.getName() + ")")));
			request.getSession().setAttribute("user", user);
		}
		return user;
	}
	public static void userOK(HttpServletRequest request) throws IOException {
		User user = (User) request.getSession().getAttribute("user");
		if (user == null) {
			user = new User(new Machine(new Server(), "grid", Catalog.getRules("grid")));
			user.getGrid().input((Symbol.parse("(user " + user.getName() + ")")));
			request.getSession().setAttribute("user", user);
		}
	}
}
